
#include <Amount.h>
#include <Unit.h>
#include <LengthFormat.h>
#include <ostream>

Amount::Amount(int value, const Unit& metric)
	:value_m(value), metric_m(metric)
{
}

Amount& Amount::getInvalidData() 
{
	static  Amount invalidData(0, INVALID_UNIT);
	return invalidData;
}

bool Amount::operator==(Amount & amount) const
{
	return (getNormalizedAmount() == amount.getNormalizedAmount()) &&
		metric_m.hasSameUnitType(amount.metric_m);
}

bool Amount::operator!=(Amount & amount) const
{
	return !(*this == amount);
}

Amount Amount::operator+(Amount & amount) const
{
	int value = getNormalizedAmount() + amount.getNormalizedAmount();
	const Unit &metric = getBaseUnit();

	return metric_m.hasSameUnitType(amount.metric_m)? Amount (value, metric) : INVALID_DATA;
}

void Amount::formatString(std::ostream& out, OutFormat& outFormat) const
{
	outFormat.outPutFormat(out, *this);
}

int Amount::getNormalizedAmount() const
{
	return metric_m.convertToNormalizedAmount(value_m);
}

const Unit& Amount::getBaseUnit() const
{
	return metric_m.getBaseUnit( );
}



